import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';

import '../../../../generated/app_strings.dart';
import '../../../utils/unit_utils.dart';
import '../worksdo/material_requisition_bean.dart';
import '../wroks/contract_paymenttermscopy.dart';

//采购合同审核
class PurContractBean extends BaseBean {
  String? Id = "";
  String? PurContractCode = ""; //采购合同号
  String? ContractOutCode = ""; //合同外部编号；
  String? PurContractName = "";
  String? ContractType = ""; //合同类型
  String getContractType(BuildContext context) {
    if (ContractType == "01") {
      return AppStrings.of(context).ContractType01; //"新签合同";
    } else if (ContractType == "02") {
      return AppStrings.of(context).ContractType02; //"续约合同";
    } else if (ContractType == "03") {
      return AppStrings.of(context).ContractType03; //"外聘合同";
    }
    return "";
  }

  String? SupplierName = ""; //供应商
  String? CompanyName = ""; //采购公司
  String? MaterialType = ""; //物料类型，MT01
  String? Status = "";
  String? PersonName = ""; //采购员
  String? NodeStatus = "";
  String? YwxName = "";
  String? wfId = "";
  String? YwxId = "";
  String? PurBodyCode = ""; //子合同编号
  String? BodyId = "";
  String? InsertDatetime = "";
  String? MaterialTypeName = ""; //物料类型名称

  ///获取物料类型名称
  String getMaterialTypeName(BuildContext context) {
    if (MaterialType == "MT01") {
      return AppStrings.of(context).Raw; //原片
    } else if (MaterialType == "MT02") {
      return AppStrings.of(context).SupplementaryMaterial; //辅料
    } else if (MaterialType == "MT03") {
      return AppStrings.of(context).Hardware; //五金
    }
    return MaterialType ?? "";
  }

  String? ReviewTypeId = "";
  String? IsApproval = "";

  ContractPaymentTerms? Cptc = null; //付款方式
  List<FileInfoBean>? FileInfo = null; //附件
  List<String>? getFileInfo() {
    if (FileInfo != null && FileInfo!.length > 0) {
      List<String> list = [];
      FileInfo?.forEach((element) {
        if (StringUtils.isNotEmpty(element.FilePatch)) {
          list.add(element.FilePatch!);
        }
      });
      return list;
    }
    return null;
  }

  List<FileInfoBean>? BodyFileInfo = null; //附件(物料信息里的查看附件)
  List<String>? getBodyFileInfo() {
    if (BodyFileInfo != null && BodyFileInfo!.length > 0) {
      List<String> list = [];
      BodyFileInfo?.forEach((element) {
        if (StringUtils.isNotEmpty(element.FilePatch)) {
          list.add(element.FilePatch!);
        }
      });
      return list;
    }
    return null;
  }

  List<PurContractListBean>? PurContractList = null; //物料信息

  List<List<PurContractListBean>?>? PurContractLists =
      null; //物料信息，根据采购单号PurOrderCode合并
  List<List<PurContractListBean>?> getPurContractLists() {
    if (PurContractLists == null || PurContractLists!.length <= 0) {
      PurContractLists = [];
      var map = <String, List<PurContractListBean>>{};
      PurContractList?.forEach((element) {
        if (element.PurOrderCode != null) {
          var lists = map[element.PurOrderCode];
          if (lists == null) {
            lists = [];
          }
          lists.add(element);
          map[element.PurOrderCode!] = lists;
        }
      });
      map?.forEach((key, value) {
        PurContractLists?.add(value);
      });
    }
    return PurContractLists!;
  }

  String? PaymentTerms = "";
  String? AdvancePercent = "";
  String? Advance = "";
  String? MinimumBalanceB = "";
  String? MinimumBalanceA = "";
  String? MidYearMonth = "";
  String? MidYearDay = "";
  String? MidYearPercent = "";
  String? MidAccountMonth = "";
  String? MidAccountDay = "";
  String? EndYearMonth = "";
  String? EndYearDay = "";
  String? EndYearPercent = "";
  String? EndAccountMonth = "";
  String? EndAccountDay = "";
  String? EndPayDay = "";
  String? DatePay = "";
  String? ReconciliationDate = "";
  String? MaxPay = "";
  String? PaymentPercent = "";
  String? BeforeMonth = "";
  String? PackageTypeName = ""; //包装要求
  String? QualityTypeName = ""; //质量标准
  String? IsSave = "";
  String? deletedContractListId = "";
  String? deletedFileListId = "";
  String? VsupplierId = "";
  String? VSupplierName = "";
  String? VSupplierAddress = "";
  String? VSupplierTel = "";
  String? VSupplierPerson = "";
  String? VSupplierFax = "";
  String? PurOrderCode = ""; //采购合同号
  String? PurCodes = "";

  // String? BodyId="";
  // String? PurBodyCode="";
  String? OutCode = ""; //子合同外部编号
  String? SignDateTime = ""; //签订日期
  String? getSignDateTime() {
    if (StringUtils.isNotEmpty(SignDateTime)) {
      if (SignDateTime!.contains("T")) {
        return SignDateTime!.split("T")[0];
      } else {
        return SignDateTime!.split(" ")[0];
      }
    }
    return "";
  }

  ///去除了T
  String? getSignDateTime2() {
    if (StringUtils.isNotEmpty(SignDateTime)) {
      if (SignDateTime!.contains("T")) {
        return SignDateTime!.replaceAll("T", "");
      } else {
        return SignDateTime;
      }
    }
    return "";
  }

  String? DeliveryDateTime = ""; //要货日期
  String? getDeliveryDateTime() {
    if (StringUtils.isNotEmpty(DeliveryDateTime)) {
      if (DeliveryDateTime!.contains("T")) {
        return DeliveryDateTime!.split("T")[0];
      } else {
        return DeliveryDateTime!.split(" ")[0];
      }
    }
    return "";
  }

  String? BodyCreater = "";
  String? BodyStatus = "";
  String? IsChange = "";

  ///是否为变更
  bool isChange() {
    if (IsChange == "1") {
      return true;
    }
    return false;
  }

  String? IsLading = "";
  String? IsStockIn = "";

  // String? MaterialType="";
  // String? Id="";
  // String? PurContractCode="";
  // String? PurContractName="";
  // String? ContractOutCode="";
  String? SupplierId = "";
  String? CompanyId = "";
  String? Creater = ""; //创建人
  String? CreateName = "";
  String? CreaterDateTime = ""; //创建日期
  ///获取创建时间；只取年月日部分。
  String? getCreaterDateTime() {
    ///fixme TakeEffectDate erp上面创建日期用的这个；所以同步一下；
    if (StringUtils.isNotEmpty(TakeEffectDate)) {
      if (TakeEffectDate!.contains("T")) {
        return TakeEffectDate!.split("T")[0];
      } else {
        return TakeEffectDate!.split(" ")[0];
      }
    }
    return TakeEffectDate;
  }

  String? TakeEffectDate = "";
  String? TerminationDate = ""; //供货日期
  String? getTerminationDate() {
    if (StringUtils.isNotEmpty(TerminationDate)) {
      if (TerminationDate!.contains("T")) {
        return TerminationDate!.split("T")[0];
      } else {
        return TerminationDate!.split(" ")[0];
      }
    }
    return "";
  }

  String? CurrencyType = ""; //结算货币

  // String? ContractType="";
  String? PackageType = "";
  String? DeliveryType = ""; //提货方式
  String getDeliveryType(BuildContext context) {
    if (DeliveryType == "1") {
      return AppStrings.of(context).DeliveryType1; //"送货上门";
    } else if (DeliveryType == "2") {
      return AppStrings.of(context).DeliveryType2; //"自提";
    }
    return "";
  }

  String? QualityType = "";
  String? IsImport = "";
  String? LinkMan = ""; //联系人
  String? Telephone = ""; //联系电话
  String? Address = ""; //联系地址
  String? Fax = "";
  String? CompanyBank = ""; //开户行
  String? BankAccount = ""; //银行账号

  // String? Status="";
  String? rate = "";
  String? Taxcode = ""; //税码
  String? SContractCode = "";
  String? ProjectName = "";
  String? ContractAmount = ""; //合同金额
  String? StatementDate = "";
  String? AdvanceOffsetMode = "";
  String? AdvanceOffsetPercent = "";
  String? AdvanceOffsetPercentFinal = "";
  String? Email = ""; //邮箱地址
  String? SourceType = ""; //来源类型
  String? PaymentType = "";
  String? BodyNum = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    Id = json['Id']?.toString() ?? "";
    PurContractCode = json['PurContractCode']?.toString() ?? "";
    ContractOutCode = json['ContractOutCode']?.toString() ?? "";
    PurContractName = json['PurContractName']?.toString() ?? "";
    ContractType = json['ContractType']?.toString() ?? "";
    SupplierName = json['SupplierName']?.toString() ?? "";
    CompanyName = json['CompanyName']?.toString() ?? "";
    MaterialType = json['MaterialType']?.toString() ?? "";
    Status = json['Status']?.toString() ?? "";
    PersonName = json['PersonName']?.toString() ?? "";
    NodeStatus = json['NodeStatus']?.toString() ?? "";
    YwxName = json['YwxName']?.toString() ?? "";
    wfId = json['wfId']?.toString() ?? "";
    YwxId = json['YwxId']?.toString() ?? "";
    PurBodyCode = json['PurBodyCode']?.toString() ?? "";
    BodyId = json['BodyId']?.toString() ?? "";
    InsertDatetime = json['InsertDatetime']?.toString() ?? "";
    MaterialTypeName = json['MaterialTypeName']?.toString() ?? "";
    ReviewTypeId = json['ReviewTypeId']?.toString() ?? "";
    IsApproval = json['IsApproval']?.toString() ?? "";
    CreateName = json['CreateName']?.toString() ?? "";
    Cptc = setGenericFromJson(json, 'Cptc', ContractPaymentTerms(), "");
    FileInfo =
        setGenericFromJson(json, 'FileInfo', <FileInfoBean>[], FileInfoBean());
    BodyFileInfo = setGenericFromJson(
        json, 'BodyFileInfo', <FileInfoBean>[], FileInfoBean());
    PaymentTerms = json['PaymentTerms']?.toString() ?? "";
    AdvancePercent = json['AdvancePercent']?.toString() ?? "";
    Advance = json['Advance']?.toString() ?? "";
    MinimumBalanceB = json['MinimumBalanceB']?.toString() ?? "";
    MinimumBalanceA = json['MinimumBalanceA']?.toString() ?? "";
    MidYearMonth = json['MidYearMonth']?.toString() ?? "";
    MidYearDay = json['MidYearDay']?.toString() ?? "";
    MidYearPercent = json['MidYearPercent']?.toString() ?? "";
    MidAccountMonth = json['MidAccountMonth']?.toString() ?? "";
    MidAccountDay = json['MidAccountDay']?.toString() ?? "";
    EndYearMonth = json['EndYearMonth']?.toString() ?? "";
    EndYearDay = json['EndYearDay']?.toString() ?? "";
    EndYearPercent = json['EndYearPercent']?.toString() ?? "";
    EndAccountMonth = json['EndAccountMonth']?.toString() ?? "";
    EndAccountDay = json['EndAccountDay']?.toString() ?? "";
    EndPayDay = json['EndPayDay']?.toString() ?? "";
    DatePay = json['DatePay']?.toString() ?? "";
    ReconciliationDate = json['ReconciliationDate']?.toString() ?? "";
    MaxPay = json['MaxPay']?.toString() ?? "";
    PaymentPercent = json['PaymentPercent']?.toString() ?? "";
    BeforeMonth = json['BeforeMonth']?.toString() ?? "";
    PackageTypeName = json['PackageTypeName']?.toString() ?? "";
    QualityTypeName = json['QualityTypeName']?.toString() ?? "";
    IsSave = json['IsSave']?.toString() ?? "";
    deletedContractListId = json['deletedContractListId']?.toString() ?? "";
    deletedFileListId = json['deletedFileListId']?.toString() ?? "";
    VsupplierId = json['VsupplierId']?.toString() ?? "";
    VSupplierName = json['VSupplierName']?.toString() ?? "";
    VSupplierAddress = json['VSupplierAddress']?.toString() ?? "";
    VSupplierTel = json['VSupplierTel']?.toString() ?? "";
    VSupplierPerson = json['VSupplierPerson']?.toString() ?? "";
    VSupplierFax = json['VSupplierFax']?.toString() ?? "";
    PurOrderCode = json['PurOrderCode']?.toString() ?? "";
    PurCodes = json['PurCodes']?.toString() ?? "";
    OutCode = json['OutCode']?.toString() ?? "";
    SignDateTime = json['SignDateTime']?.toString() ?? "";
    DeliveryDateTime = json['DeliveryDateTime']?.toString() ?? "";
    BodyCreater = json['BodyCreater']?.toString() ?? "";
    BodyStatus = json['BodyStatus']?.toString() ?? "";
    IsChange = json['IsChange']?.toString() ?? "";
    IsLading = json['IsLading']?.toString() ?? "";
    IsStockIn = json['IsStockIn']?.toString() ?? "";
    SupplierId = json['SupplierId']?.toString() ?? "";
    CompanyId = json['CompanyId']?.toString() ?? "";
    Creater = json['Creater']?.toString() ?? "";
    CreateName = json['CreateName']?.toString() ?? "";
    CreaterDateTime = json['CreaterDateTime']?.toString() ?? "";
    TakeEffectDate = json['TakeEffectDate']?.toString() ?? "";
    TerminationDate = json['TerminationDate']?.toString() ?? "";
    CurrencyType = json['CurrencyType']?.toString() ?? "";
    PackageType = json['PackageType']?.toString() ?? "";
    DeliveryType = json['DeliveryType']?.toString() ?? "";
    QualityType = json['QualityType']?.toString() ?? "";
    IsImport = json['IsImport']?.toString() ?? "";
    LinkMan = json['LinkMan']?.toString() ?? "";
    Telephone = json['Telephone']?.toString() ?? "";
    Address = json['Address']?.toString() ?? "";
    Fax = json['Fax']?.toString() ?? "";
    CompanyBank = json['CompanyBank']?.toString() ?? "";
    BankAccount = json['BankAccount']?.toString() ?? "";
    rate = json['rate']?.toString() ?? "";
    Taxcode = json['Taxcode']?.toString() ?? "";
    SContractCode = json['SContractCode']?.toString() ?? "";
    ProjectName = json['ProjectName']?.toString() ?? "";
    ContractAmount = json['ContractAmount']?.toString() ?? "";
    StatementDate = json['StatementDate']?.toString() ?? "";
    AdvanceOffsetMode = json['AdvanceOffsetMode']?.toString() ?? "";
    AdvanceOffsetPercent = json['AdvanceOffsetPercent']?.toString() ?? "";
    AdvanceOffsetPercentFinal =
        json['AdvanceOffsetPercentFinal']?.toString() ?? "";
    Email = json['Email']?.toString() ?? "";
    SourceType = json['SourceType']?.toString() ?? "";
    PaymentType = json['PaymentType']?.toString() ?? "";
    BodyNum = json['BodyNum']?.toString() ?? "";
    PurContractList = setGenericFromJson(json, "PurContractList",
        <PurContractListBean>[], PurContractListBean());
  }

  @override
  instance() {
    // TODO: implement instance
    return PurContractBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["Id"] = Id;
    map["PurContractCode"] = PurContractCode;
    map["ContractOutCode"] = ContractOutCode;
    map["PurContractName"] = PurContractName;
    map["ContractType"] = ContractType;
    map["SupplierName"] = SupplierName;
    map["CompanyName"] = CompanyName;
    map["MaterialType"] = MaterialType;
    map["Status"] = Status;
    map["PersonName"] = PersonName;
    map["NodeStatus"] = NodeStatus;
    map["YwxName"] = YwxName;
    map["wfId"] = wfId;
    map["YwxId"] = YwxId;
    map["PurBodyCode"] = PurBodyCode;
    map["BodyId"] = BodyId;
    map["InsertDatetime"] = InsertDatetime;
    map["MaterialTypeName"] = MaterialTypeName;
    map["ReviewTypeId"] = ReviewTypeId;
    map["IsApproval"] = IsApproval;
    map["CreateName"] = CreateName;
    map["Cptc"] = Cptc;
    map["FileInfo"] = FileInfo;
    map["PaymentTerms"] = PaymentTerms;
    map["AdvancePercent"] = AdvancePercent;
    map["Advance"] = Advance;
    map["MinimumBalanceB"] = MinimumBalanceB;
    map["MinimumBalanceA"] = MinimumBalanceA;
    map["MidYearMonth"] = MidYearMonth;
    map["MidYearDay"] = MidYearDay;
    map["MidYearPercent"] = MidYearPercent;
    map["MidAccountMonth"] = MidAccountMonth;
    map["MidAccountDay"] = MidAccountDay;
    map["EndYearMonth"] = EndYearMonth;
    map["EndYearDay"] = EndYearDay;
    map["EndYearPercent"] = EndYearPercent;
    map["EndAccountMonth"] = EndAccountMonth;
    map["EndAccountDay"] = EndAccountDay;
    map["EndPayDay"] = EndPayDay;
    map["DatePay"] = DatePay;
    map["ReconciliationDate"] = ReconciliationDate;
    map["MaxPay"] = MaxPay;
    map["PaymentPercent"] = PaymentPercent;
    map["BeforeMonth"] = BeforeMonth;
    map["PackageTypeName"] = PackageTypeName;
    map["QualityTypeName"] = QualityTypeName;
    map["IsSave"] = IsSave;
    map["deletedContractListId"] = deletedContractListId;
    map["deletedFileListId"] = deletedFileListId;
    map["VsupplierId"] = VsupplierId;
    map["VSupplierName"] = VSupplierName;
    map["VSupplierAddress"] = VSupplierAddress;
    map["VSupplierTel"] = VSupplierTel;
    map["VSupplierPerson"] = VSupplierPerson;
    map["VSupplierFax"] = VSupplierFax;
    map["PurOrderCode"] = PurOrderCode;
    map["PurCodes"] = PurCodes;
    map["OutCode"] = OutCode;
    map["SignDateTime"] = SignDateTime;
    map["DeliveryDateTime"] = DeliveryDateTime;
    map["BodyCreater"] = BodyCreater;
    map["BodyStatus"] = BodyStatus;
    map["IsChange"] = IsChange;
    map["IsLading"] = IsLading;
    map["IsStockIn"] = IsStockIn;
    map["SupplierId"] = SupplierId;
    map["CompanyId"] = CompanyId;
    map["Creater"] = Creater;
    map["CreateName"] = CreateName;
    map["CreaterDateTime"] = CreaterDateTime;
    map["TakeEffectDate"] = TakeEffectDate;
    map["TerminationDate"] = TerminationDate;
    map["CurrencyType"] = CurrencyType;
    map["PackageType"] = PackageType;
    map["DeliveryType"] = DeliveryType;
    map["QualityType"] = QualityType;
    map["IsImport"] = IsImport;
    map["LinkMan"] = LinkMan;
    map["Telephone"] = Telephone;
    map["Address"] = Address;
    map["Fax"] = Fax;
    map["CompanyBank"] = CompanyBank;
    map["BankAccount"] = BankAccount;
    map["rate"] = rate;
    map["Taxcode"] = Taxcode;
    map["SContractCode"] = SContractCode;
    map["ProjectName"] = ProjectName;
    map["ContractAmount"] = ContractAmount;
    map["StatementDate"] = StatementDate;
    map["AdvanceOffsetMode"] = AdvanceOffsetMode;
    map["AdvanceOffsetPercent"] = AdvanceOffsetPercent;
    map["AdvanceOffsetPercentFinal"] = AdvanceOffsetPercentFinal;
    map["Email"] = Email;
    map["SourceType"] = SourceType;
    map["PaymentType"] = PaymentType;
    map["BodyNum"] = BodyNum;
    map["PurContractList"] = PurContractList;
    map["BodyFileInfo"] = BodyFileInfo;
    return map;
  }
}

// {
// "FileId": "8462",
// "FilePatch": "http:/localhost:30929/UploadFile/PurchaseFile/20220531287951/002.jpeg",
// "FileSize": "18558",
// "FileType": "jpeg",
// "FileName": "002.jpeg"
// }
///附件
class FileInfoBean extends BaseBean {
  String? FileId = "";
  String? FilePatch = "";
  String? FileSize = "";
  String? FileType = "";
  String? FileName = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    FileId = json['FileId']?.toString() ?? "";
    FilePatch = json['FilePatch']?.toString() ?? "";
    FileSize = json['FileSize']?.toString() ?? "";
    FileType = json['FileType']?.toString() ?? "";
    FileName = json['FileName']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return FileInfoBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["FileId"] = FileId;
    map["FilePatch"] = FilePatch;
    map["FileSize"] = FileSize;
    map["FileType"] = FileType;
    map["FileName"] = FileName;
    return map;
  }
}

///物料信息
class PurContractListBean extends BaseBean {
  String? PurCode = ""; //请购单号

  String? POMinNum = ""; //fixme 请购数量
  String? POMainUnit = ""; //单位
  String? MaterialType = "";
  String? Thickness = "";
  String? PurOrderCode = ""; //采购单号
  String? QualityGrade = ""; //质量等级
  String? QualityGradeName = "";
  String? ChangeManufacturerId = "";
  String? ChangeManufacturerName = "";
  String? ChangePrice = "";
  String? ChangeAreaPrice = "";
  String? ChangeQualityGrade = "";
  String? ChangeQualityGradeName = "";
  String? IsChange = "";

  ///fixme（1和0）判断；为1时显示；价格，质量等级和品牌；如果为0；就不用做变红的判断了。为1才需要。
  ///品牌  折算面积单价 单价 质量等级
  bool isChange() {
    if (IsChange == "1") {
      return true;
    }
    return false;
  }

  String? Quantity = ""; //已申请数量
  String? Thickness2 = ""; //厚度；采购合同物料信息，用这个。
  String? lengths = "";
  String? numbers = "";
  String? ListId = "";
  String? PCId = "";
  String? POListId = "";
  String? MaterialTypeId = "";
  String? MaterialCode = "";
  String? MaterialName = "";
  String? ProjectId = "";
  String? MainNum = ""; //采购数量
  String? MainUnit = "";
  String? SubsidiaryNum = ""; //辅数量（ 面积）
  String? SubsidiaryUnit = ""; //辅数量单位
  String? Width = "";
  String? Height = "";
  String? Size = ""; //型号
  String? ManufacturerId = "";
  String? ManufacturerName = "";
  String? PriceUnit = "";
  String? Price = ""; //单价
  String? Amount = ""; //金额
  String? PurContractCode = "";
  String? LadingNum = "";
  String? tons = "";
  String? tonsprice = ""; //顿重单价
  String? areaprice = ""; //折算面积单价
  String? ListBeizhu = ""; //备注

  ///新加字段；
  String? PackageUnit = ""; //包的单位
  String? WidthUnit = ""; //宽单位
  String? HeightUnit = ""; //高单位
  String? LengthUnit = ""; //长单位
  String? ThicknessUnit = ""; //厚度单位
  String? PackageCount = ""; //包数量
  String? PackageListCount = ""; //每包数量

  //数量单位
  String? QuantityUnit = "";

  ///获取数量，并且带单位。
  String? getNumbersStrAndUnit() {
    // return "${AppUnitUtils.getStringAs0(Numbers)}${QuantityUnit}";
    return "${StringUtils.toStringAsDecimal(numbers)}${QuantityUnit}";
  }

  double toDouble(String? num) {
    if (StringUtils.isEmpty(num)) {
      return 1;
    } else {
      try {
        var d = double.parse(num!);
        if (d <= 0) {
          return 1; //小于等于0的作1处理。
        }
        return d;
      } catch (e) {}
    }
    return 1;
  }

  String? WidthInput = ""; //记录手动输入的。(自己加的本地参数)
  double Width2() {
    var num = Width ?? "1";
    return toDouble(num);
  }
  ///获取宽；
  String? getWidthInput() {
    if (StringUtils.isEmpty(WidthInput)) {
      //Width:============================0.0
      //print("Width:============================${Width}");
      //fixme 毫米转化为其他对应的单位；服务器默认传递的都是毫米。最后我们提交的时候，还需要再转化为毫米再提交给服务器。
      if (StringUtils.isEmpty(Width) || Width == "0" || Width == "0.0") {
        WidthInput = "0";
      } else {
        WidthInput =
            AppUnitUtils.mmtoUnit(WidthUnit, Width2().toString()).toString();
        WidthInput = StringUtils.toStringAsDecimal(WidthInput);
      }
    }
    return WidthInput;
  }

  double Height2() {
    var num = Height ?? "1";
    return toDouble(num);
  }

  String? HeightInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取高；
  String? getHeightInput() {
    if (StringUtils.isEmpty(HeightInput)) {
      //毫米转化为其他对应的单位；服务器默认传递的都是毫米。
      if (StringUtils.isEmpty(Height) || Height == "0" || Height == "0.0") {
        HeightInput = "0";
      } else {
        HeightInput =
            AppUnitUtils.mmtoUnit(HeightUnit, Height2().toString()).toString();
        HeightInput = StringUtils.toStringAsDecimal(HeightInput);
      }
    }
    return HeightInput;
  }

  double Lengths2() {
    var num = lengths ?? "1";
    return toDouble(num);
  }

  String? LengthsInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取长；
  String? getLengthsInput() {
    if (StringUtils.isEmpty(LengthsInput)) {
      //毫米转化为其他对应的单位；服务器默认传递的都是毫米。
      if (StringUtils.isEmpty(lengths) || lengths == "0" || lengths == "0.0") {
        LengthsInput = "0";
      } else {
        LengthsInput =
            AppUnitUtils.mmtoUnit(LengthUnit, Lengths2().toString()).toString();
        LengthsInput = StringUtils.toStringAsDecimal(LengthsInput);
      }
    }
    return LengthsInput;
  }

  double Thickness3() {
    var num = Thickness2 ?? "1";
    return toDouble(num);
  }

  String? ThicknessInput = ""; //记录手动输入的。(自己加的本地参数)
  ///获取厚；
  String? getThicknessInput() {
    if (StringUtils.isEmpty(ThicknessInput)) {
      //毫米转化为其他对应的单位；服务器默认传递的都是毫米。
      if (StringUtils.isEmpty(Thickness2) ||
          Thickness2 == "0" ||
          Thickness2 == "0.0") {
        ThicknessInput = "0";
      } else {
        ThicknessInput =
            AppUnitUtils.mmtoUnit(ThicknessUnit, Thickness3().toString())
                .toString();
        ThicknessInput = StringUtils.toStringAsDecimal(ThicknessInput);
      }
    }
    return ThicknessInput;
  }

  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    PurCode = json['PurCode']?.toString() ?? "";
    POMinNum = json['POMinNum']?.toString() ?? "";
    POMainUnit = json['POMainUnit']?.toString() ?? "";
    MaterialType = json['MaterialType']?.toString() ?? "";
    Thickness = json['Thickness']?.toString() ?? "";
    PurOrderCode = json['PurOrderCode']?.toString() ?? "";
    QualityGradeName = json['QualityGradeName']?.toString() ?? "";
    ChangeManufacturerId = json['ChangeManufacturerId']?.toString() ?? "";
    ChangeManufacturerName = json['ChangeManufacturerName']?.toString() ?? "";
    ChangePrice = json['ChangePrice']?.toString() ?? "";
    ChangeAreaPrice = json['ChangeAreaPrice']?.toString() ?? "";
    ChangeQualityGrade = json['ChangeQualityGrade']?.toString() ?? "";
    ChangeQualityGradeName = json['ChangeQualityGradeName']?.toString() ?? "";
    IsChange = json['IsChange']?.toString() ?? "";
    Quantity = json['Quantity']?.toString() ?? "";
    Thickness2 = json['Thickness2']?.toString() ?? "";
    lengths = json['lengths']?.toString() ?? "";
    numbers = json['numbers']?.toString() ?? "";
    ListId = json['ListId']?.toString() ?? "";
    PCId = json['PCId']?.toString() ?? "";
    POListId = json['POListId']?.toString() ?? "";
    MaterialTypeId = json['MaterialTypeId']?.toString() ?? "";
    MaterialCode = json['MaterialCode']?.toString() ?? "";
    MaterialName = json['MaterialName']?.toString() ?? "";
    ProjectId = json['ProjectId']?.toString() ?? "";
    MainNum = json['MainNum']?.toString() ?? "";
    MainUnit = json['MainUnit']?.toString() ?? "";
    SubsidiaryNum = json['SubsidiaryNum']?.toString() ?? "";
    SubsidiaryUnit = json['SubsidiaryUnit']?.toString() ?? "";
    Width = json['Width']?.toString() ?? "";
    Height = json['Height']?.toString() ?? "";
    Size = json['Size']?.toString() ?? "";
    ManufacturerId = json['ManufacturerId']?.toString() ?? "";
    ManufacturerName = json['ManufacturerName']?.toString() ?? "";
    PriceUnit = json['PriceUnit']?.toString() ?? "";
    Price = json['Price']?.toString() ?? "";
    Amount = json['Amount']?.toString() ?? "";
    PurContractCode = json['PurContractCode']?.toString() ?? "";
    LadingNum = json['LadingNum']?.toString() ?? "";
    tons = json['tons']?.toString() ?? "";
    tonsprice = json['tonsprice']?.toString() ?? "";
    areaprice = json['areaprice']?.toString() ?? "";
    QualityGrade = json['QualityGrade']?.toString() ?? "";
    ListBeizhu = json['ListBeizhu']?.toString() ?? "";
    //江勇新加字段
    PackageUnit = json["PackageUnit"]?.toString() ?? "";
    WidthUnit = json["WidthUnit"]?.toString() ?? "";
    HeightUnit = json["HeightUnit"]?.toString() ?? "";
    LengthUnit = json["LengthUnit"]?.toString() ?? "";
    ThicknessUnit = json["ThicknessUnit"]?.toString() ?? "";
    PackageCount = json["PackageCount"]?.toString() ?? "";
    PackageListCount = json["PackageListCount"]?.toString() ?? "";
    QuantityUnit= json["QuantityUnit"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return PurContractListBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["PurCode"] = PurCode;
    map["POMinNum"] = POMinNum;
    map["POMainUnit"] = POMainUnit;
    map["MaterialType"] = MaterialType;
    map["Thickness"] = Thickness;
    map["PurOrderCode"] = PurOrderCode;
    map["QualityGradeName"] = QualityGradeName;
    map["ChangeManufacturerId"] = ChangeManufacturerId;
    map["ChangeManufacturerName"] = ChangeManufacturerName;
    map["ChangePrice"] = ChangePrice;
    map["ChangeAreaPrice"] = ChangeAreaPrice;
    map["ChangeQualityGrade"] = ChangeQualityGrade;
    map["ChangeQualityGradeName"] = ChangeQualityGradeName;
    map["IsChange"] = IsChange;
    map["Quantity"] = Quantity;
    map["Thickness2"] = Thickness2;
    map["lengths"] = lengths;
    map["numbers"] = numbers;
    map["ListId"] = ListId;
    map["PCId"] = PCId;
    map["POListId"] = POListId;
    map["MaterialTypeId"] = MaterialTypeId;
    map["MaterialCode"] = MaterialCode;
    map["MaterialName"] = MaterialName;
    map["ProjectId"] = ProjectId;
    map["MainNum"] = MainNum;
    map["MainUnit"] = MainUnit;
    map["SubsidiaryNum"] = SubsidiaryNum;
    map["SubsidiaryUnit"] = SubsidiaryUnit;
    map["Width"] = Width;
    map["Height"] = Height;
    map["Size"] = Size;
    map["ManufacturerId"] = ManufacturerId;
    map["ManufacturerName"] = ManufacturerName;
    map["PriceUnit"] = PriceUnit;
    map["Price"] = Price;
    map["Amount"] = Amount;
    map["PurContractCode"] = PurContractCode;
    map["LadingNum"] = LadingNum;
    map["tons"] = tons;
    map["tonsprice"] = tonsprice;
    map["areaprice"] = areaprice;
    map["QualityGrade"] = QualityGrade;
    map["ListBeizhu"] = ListBeizhu;
    //江勇新加字段
    map["PackageUnit"] = PackageUnit;
    map["WidthUnit"] = WidthUnit;
    map["HeightUnit"] = HeightUnit;
    map["LengthUnit"] = LengthUnit;
    map["ThicknessUnit"] = ThicknessUnit;
    map["PackageCount"] = PackageCount;
    map["PackageListCount"] = PackageListCount;
    map["QuantityUnit"] = QuantityUnit;
    return map;
  }

  ///判断是否为原片
  bool isMT01() {
    if (MaterialType == PurDemand.MT01) {
      return true;
    }
    return false;
  }

  ///判断是否为辅料
  bool isMT02() {
    if (MaterialType == PurDemand.MT02) {
      return true;
    }
    return false;
  }

  /// 是否显示宽
  bool Iswidth2() {
    return true;
  }

  /// 是否显示高
  bool Isheight2() {
    return true;
  }

  /// 是否显示厚
  bool Isthickness2() {
    if (isMT01()) {
      return false; //原片不显示
    }
    return true;
  }

  /// 是否显示长
  bool Islength2() {
    if (isMT01()) {
      return false; //原片不显示
    }
    return true;
  }

  ///是否显示数量
  bool Isquantity2() {
    if (isMT01()) {
      return false; //原片不显示
    }
    return true;
  }

  ///是否显示辅数量（面积）
  bool isSubsidiaryNum() {
    /// 物料类型  MT01：原片 MT02：辅料 MT03：五金
    //String? MaterialType = "";
    if (MaterialType == PurDemand.MT01) {
      return true;
    }
    return false;
  }

  ///是否显示来源类型
  bool isSourceType() {
    if (MaterialType == PurDemand.MT01) {
      return false; //原片没有
    }
    return true;
  }

  ///是否显示单价
  bool isPrice() {
    if (MaterialType == PurDemand.MT01) {
      return false; //原片没有
    }
    return true;
  }

  ///是否显示金额
  bool isAmount() {
    if (MaterialType == PurDemand.MT01) {
      return false; //原片没有
    }
    return true;
  }

  ///获取物料类型名称
  String getMaterialTypeName(BuildContext context) {
    if (MaterialType == "MT01") {
      return AppStrings.of(context).Raw; //原片
    } else if (MaterialType == "MT02") {
      return AppStrings.of(context).SupplementaryMaterial; //辅料
    } else if (MaterialType == "MT03") {
      return AppStrings.of(context).Hardware; //五金
    }
    return "";
  }
}
